package com.scatteredServer.controller;

import com.scatteredServer.common.Result;
import com.scatteredServer.pojo.form.add.AddPosting;
import com.scatteredServer.pojo.form.add.AddPostingNotice;
import com.scatteredServer.pojo.form.update.UpdatePostingDetails;
import com.scatteredServer.pojo.form.update.UpdateRoughlyPosting;
import com.scatteredServer.pojo.query.PostingQuery;
import com.scatteredServer.pojo.vo.*;
import com.scatteredServer.service.impl.PostingServiceImpl;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("s4/posting")
@Slf4j
@Tag(name = "发文管理", description = "发文管理")
public class PostingController {

    @Autowired
    PostingServiceImpl postingService;


    @Operation(summary = "查询获取(粗略信息)", description = "查询获取（粗略信息）")
    @PostMapping("/getList")
    public Result<BaseVo<PostingRoughlyVo>> getList(@RequestBody PostingQuery postingQuery) {
        return postingService.getList(postingQuery);
    }

    @Operation(summary = "教师：查询获取(粗略信息)", description = "查询获取（粗略信息）")
    @PostMapping("/getListByTeacherId")
    public Result<BaseVo<PostingRoughlyTeacherVo>> getListByTeacherId(@RequestBody PostingQuery postingQuery) {
        return postingService.getListByTeacherId(postingQuery);
    }

    @Operation(summary = "修改(粗略信息)", description = "查询获取（粗略信息）")
    @PostMapping("/updateRoughlyById")
    public Result<String> updateRoughlyById(@RequestBody UpdateRoughlyPosting updateRoughlyPosting) {
        return postingService.updateRoughlyById(updateRoughlyPosting);
    }

    @Operation(summary = "查询获取详情", description = "查询获取详情")
    @PostMapping("/getDetailsById/{id}")
    public Result<PostingDetailsVo> getDetailsById(@PathVariable String id) {
        return postingService.getDetailsById(id);
    }

    @Operation(summary = "修改详情", description = "查询详情")
    @PostMapping("/updateDetailsById")
    public Result<String> updateDetailsById(@RequestBody UpdatePostingDetails updatePostingDetails) {
        return postingService.updateDetailsById(updatePostingDetails);
    }


    @Operation(summary = "添加一个发文", description = "添加一个发文")
    @PostMapping("/addOne")
    public Result<String> addOne(@RequestBody AddPosting addPosting) {
        return postingService.addOne(addPosting);
    }

    @Operation(summary = "获取教师id和教师姓名对应的下列选择列表", description = "获取教师id和教师姓名对应的下列选择列表")
    @GetMapping("/getSelector")
    public Result<List<TeacherInfoMap>> getSelector() {
        return postingService.getSelector();
    }

    @Operation(summary = "批量删除发文", description = "批量删除发文")
    @PostMapping("/deleteByIds")
    public Result<String> deleteByIds(@RequestBody List<Integer> list) {
        return postingService.deleteByIds(list);
    }

    @Operation(summary = "添加文章的指定教师", description = "修改文章指定哪些教师可以看")
    @PostMapping("/addTeachersForPosting")
    public Result<String> addTeachersForPosting(@RequestBody AddPostingNotice addPostingNotice) {
        return postingService.addTeachersForPosting(addPostingNotice);
    }

    @Operation(summary = "删除文章的指定教师", description = "修改文章指定哪些教师可以看")
    @PostMapping("/deleteTeachersForPosting")
    public Result<String> deleteTeachersForPosting(@RequestBody AddPostingNotice addPostingNotice) {
        return postingService.deleteTeachersForPosting(addPostingNotice);
    }


}
